import { http } from '@/plugins/axios'
import useUtils from '@/utils'

const { encodeSearchParams } = useUtils()
export default () => {
  const index = async (page: number = 0, obj: Object) => {
    let data = encodeSearchParams(obj)
    return await http.request<any>({
      url: `record?page=${page}&${data}`,
      method: 'GET',
    })
  }
  // 新增
  const store = async (data: RecordModel) => {
    return await http.request<any>({
      url: `record`,
      method: 'POST',
      data: data,
    })
  }
  const update = async (data: RecordModel) => {
    return await http.request<any>({
      url: `record/${data.id}`,
      method: 'PUT',
      data: data,
    })
  }
  const destory = async (id: number) => {
    await http.request<any>({
      url: `record/${id}`,
      method: 'DELETE',
    })
  }

  const exportRecords = async (user_id: number) => {
    return await http.request<any>({

      url: `record/export`,
      method: 'post',
      data: { user_id: user_id },
    })
  }
  const recordweekrank = async () => {
    return await http.request<any>({
      url: `record/weekrank`,
      method: 'get',
    })
  }

  const recordmonthrank = async () => {
    return await http.request<any>({
      url: `record/monthrank`,
      method: 'get',
    })
  }

  const recorddayrank = async () => {
    return await http.request<any>({
      url: `record/dayrank`,
      method: 'get',
    })
  }
  const recordCheck = async (wechat_id: string) => {
    return await http.request<any>({
      url: `record/check`,
      method: 'post',
      data: { wechat_id: wechat_id },
    })
  }
  const trashed = async (page: number = 0, obj: Object) => {
    let data = encodeSearchParams(obj)
    return await http.request<any>({
      url: `record/trashed?page=${page}&${data}`,
      method: 'GET',
    })
  }
  return {
    index,
    store,
    update,
    destory,
    exportRecords,
    recorddayrank,
    recordweekrank,
    recordmonthrank,
    recordCheck,
    trashed
  }
}